package com.imddysc.jzknavigator.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ZknaviUtils {

	private static final Logger logger = LoggerFactory.getLogger(ZknaviUtils.class);
		
	public static Map pathHref(String path) {
		String path1 = path.replace("|","/");
		logger.info("index: " + path1);
		String strArray[] = path1.split("/");
		String strArray2[] = Arrays.copyOfRange(strArray, 0, strArray.length);
		String dstrArray[] = new String[strArray2.length];
		String fstrArray[] = new String[strArray2.length];
		List pathAHrefList = new ArrayList();
		logger.info(Arrays.toString(strArray));
		logger.info(Arrays.toString(strArray2));
		for (int i = 1; i < strArray2.length; i++ ) {
			
			String d = "";
			String f = "";
			for ( int j = 1; j <= i; j++ ) {
				String t = "/" + strArray2[j];
				logger.info("t: " + t);
				d = d + t;
				if (j == i ) {
					f = t;
				}
			}
			dstrArray[i] = d;
			fstrArray[i] = f;
			PathAHref pathAHref = new PathAHref(f,d,d.replace("/", "|"));
			pathAHrefList.add(pathAHref);
		}
		
		logger.info(Arrays.toString(dstrArray));
		logger.info(Arrays.toString(fstrArray));
		
		Map map = new HashMap();
		map.put("dstrArray", dstrArray);
		map.put("fstrArray", fstrArray);
		if(pathAHrefList.size() == 0) {
			pathAHrefList.add(new PathAHref("/","/","|") );
		}
		map.put("pathAHrefList", pathAHrefList);
		map.put("pathUrl", path1.replace("/", "|"));
		map.put("pathOldUrl", path1);
		return map;
		
	}
}
